package utils;

import java.sql.*;

//数据库操作类
public class DBUtil {
	private static Connection conn = null;
	private static final  String DBDriver = "com.mysql.jdbc.Driver";
	private static final  String ConnStr = "jdbc:mysql://localhost:3306/player";
	private static final  String MyUser = "root"; // 用户名
	private static final  String MyPassword = "root";

	private DBUtil() {

	}

	public static Connection getInstance() {
		if (conn == null) {
			try {
				Class.forName(DBDriver);
				conn = DriverManager.getConnection(ConnStr, MyUser, MyPassword);
			} catch (Exception e) {
				System.err.println(e.getMessage());
			}
		}
		return conn;
	}

	public static void close(Connection connection) {
		if (connection != null)
			try {
				connection.close();
			} catch (SQLException e) {
				System.err.println(e.getMessage());
			}

	}
}